#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
        int n;
        cin>>n;
        vector<int> high(n);
        for(int i = 0; i < n; i++){
                cin >> high[i]; 
        }

        vector<int> reverse_high = high;
        reverse(reverse_high.begin(), reverse_high.end());

        vector<int> dph(n, 1);
        vector<int> dpr(n, 1);
        for(int i = 1; i < n; i++){
                for(int j = 0; j < i; j++){
                        if(high[i] > high[j]){
                                dph[i] = max(dph[i], dph[j] + 1);
                        }
                        if(reverse_high[i] > reverse_high[j]){
                                dpr[i] = max(dpr[i], dpr[j] + 1);
                        }
                }
        }

        int max_length = 0, sel = 0;
        for(int i = 0; i < n; i++){
                int current_length = dph[i] + dpr[n - i - 1] - 1;
                if(current_length > max_length){
                        max_length = current_length;
                        sel = i;
                }
        }
        cout<<n - max_length << endl;
        return 0;
}